import numpy as np
#from matplotlib import pyplot
import sys


def Lboundary(x, lx):
    res=x
    while x>=lx:
        x-=lx
    while x<0:
        x+=lx
    return x

def boundary(pos, lx,ly,lz):
    pos[0]=Lboundary(pos[0],lx)
    pos[1]=Lboundary(pos[1],ly)
    pos[2]=Lboundary(pos[2],lz)
    return pos


def anint(x, lx):
    res=x
    if x>0.5*lx:
        res-=lx
    elif x<-0.5*lx:
        res+=lx
    return res

def distancia2(lx,ly,lz,pos1, pos2, i):
    dis2=0
    drx=pos1[i][0]-pos2[i][0]
    drx=anint(drx, lx)
    dry=pos1[i][1]-pos2[i][1]
    dry=anint(dry, ly)
    drz=pos1[i][2]-pos2[i][2]
    drz=anint(drz, lz)
    drx2=drx*drx
    dry2=dry*dry
    drz2=drz*drz
    dis2=drx2+dry2+drz2
    return  [dis2,drx2,dry2,drz2]

def loadConfig(f):
    #f = open(name,'r')
    tx = f.readline()
    tx = tx.replace('\n','')
    val = tx.split(' ')
    aux=[]
    for v in val:
        if v!='':
            aux.append(v)
    t=float(aux[1])
    tcorr=float(aux[3])
    icorr=int(aux[5])
    npart=int(aux[7])
    lx=float(aux[9])
    ly=float(aux[10])
    lz=float(aux[11])
    tx = f.readline()
    tx = tx.replace('\n','')
    val = tx.split(' ')
    aux=[]
    for v in val:
        if v!='':
            aux.append(v)
    sigma=[float(aux[1]),float(aux[2]),float(aux[3]),float(aux[4]),float(aux[5]),float(aux[6])]
    pos=[]
    vel=[]
    force=[]
    diameter=[]
    
    for i in range(npart):
        tx = f.readline()
        tx = tx.replace('\n','')
        val = tx.split(' ')
        aux=[]
        for v in val:
            if v!='':
                aux.append(v)
    
        xpos=boundary([float(aux[0]),float(aux[1]),float(aux[2])], lx,ly,lz)
        pos.append(xpos)
        vel.append([float(aux[3]),float(aux[4]),float(aux[5])])
        force.append([float(aux[6]),float(aux[7]),float(aux[8])])
        diameter.append(float(aux[9]))
        
        return [pos,vel,force, diameter,sigma[0]]

name=''

f = open(name,'r')
